#include "HelloDirect3D.h"

HelloDirect3D::HelloDirect3D(HINSTANCE hInstance, std::string winCaption)
: D3DApp(hInstance, winCaption, D3DDEVTYPE_HAL, D3DCREATE_HARDWARE_VERTEXPROCESSING)
{
	D3DXFONT_DESC fontDesc;
	fontDesc.Height = 80;
	fontDesc.Width = 40;
	fontDesc.MipLevels = 0;
	fontDesc.Italic = true;
	fontDesc.CharSet = DEFAULT_CHARSET;
	fontDesc.OutputPrecision = OUT_DEFAULT_PRECIS;
	fontDesc.Quality = DEFAULT_QUALITY;
	fontDesc.PitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
	_tcscpy(fontDesc.FaceName, _T("Time new Roman"));

	D3DXCreateFontIndirect(gD3DDevice, &fontDesc, &mFont);
}

HelloDirect3D::~HelloDirect3D()
{
	ReleaseCOM(mFont);
}

void HelloDirect3D::OnLostDevice()
{
	HR(mFont->OnLostDevice());
}

void HelloDirect3D::OnResetDevice()
{
	HR(mFont->OnResetDevice());
}

void HelloDirect3D::Update(double dt)
{
}

void HelloDirect3D::Draw()
{
	gD3DDevice->Clear(0, 0,
		D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,
		D3DCOLOR_XRGB(255, 255, 255),
		1.0f, 0);

	RECT r;
	GetClientRect(GetMainWindow(), &r);

	HR(gD3DDevice->BeginScene());
	
	mFont->DrawText(0, _T("Hello Direct 3D!"),
		-1, &r,
		DT_CENTER | DT_VCENTER,
		D3DCOLOR_XRGB(rand() % 256, rand() % 256, rand() % 256));

	HR(gD3DDevice->EndScene());

	HR(gD3DDevice->Present(0,0,0,0));
}

